package com.amigo.online.provider.sync.convert.impl;

import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.provider.common.entity.MusicMysqlInfo;
import com.amigo.online.provider.sync.abs.BasicSolrDataProjectProperties;
import com.amigo.online.provider.sync.convert.ConvertJsonObjectService;

/**
 * @version: V 1.0.0
 * @Description: （MYSQL 和  Solr 对应Music对象实体转换）
 * @author: zxy QQ:1363320658
 * @date: 2018年12月10日 下午4:20:18
 */
@Service("solrMusicConvertServiceImpl")
public class SolrMusicConvertServiceImpl
        implements ConvertJsonObjectService<SolrInputDocument, JSONObject, MusicMysqlInfo> {

    @Autowired
    BasicSolrDataProjectProperties basicSolrDataProjectProperties;

    @Override
    public SolrInputDocument convert(JSONObject source) {
        SolrInputDocument document = new SolrInputDocument();
        for (String temp : basicSolrDataProjectProperties.getMusicUpdateList()) {
            document.addField(temp, source.get(temp));
        }

        /*
         * document.addField("author", source.getInteger("author")); //作者
         * document.addField("type", source.getInteger("type")); //音乐用户id
         * document.addField("recommended", source.getInteger("recommended"));//音乐名
         * document.addField("cover", source.getString("cover"));
         * document.addField("music",source.getString("music"));
         * document.addField("user_id", source.getString("user_id"));
         * document.addField("name", source.getString("name")); document.addField("id",
         * source.getInteger("id").toString()); //音乐id document.addField("category",
         * source.getInteger("category")); document.addField("video_id",
         * source.getInteger("video_id"));
         */
        return document;
    }

    @Override
    public SolrInputDocument convertBeanToObject(MusicMysqlInfo source) {
        SolrInputDocument document = new SolrInputDocument();
        document.addField("author", source.getAuthor()); // 作者
        document.addField("type", source.getType()); // 音乐用户id
        document.addField("recommended", source.getRecommended());// 音乐名
        document.addField("cover", source.getCover());
        document.addField("music", source.getMusic());
        document.addField("user_id", source.getUserId());
        document.addField("name", source.getName());
        document.addField("id", source.getId()); // 音乐id
        document.addField("category", source.getCategory());
        document.addField("video_id", source.getVideoId());
        return document;
    }

}
